#include "file.h"
#include <stdio.h>

float read_tem()
{
    float raw, offset, scale, value;
    read_file("/sys/bus/iio/devices/iio:device0/in_temp_raw", &raw);
    read_file("/sys/bus/iio/devices/iio:device0/in_temp_offset", &offset);
    read_file("/sys/bus/iio/devices/iio:device0/in_temp_scale", &scale);

    value = (raw + offset)*scale / 1000;

    return value;
}

float read_hum()
{
    float raw, offset, scale, value;
    read_file("/sys/bus/iio/devices/iio:device0/in_humidityrelative_raw", &raw);
    read_file("/sys/bus/iio/devices/iio:device0/in_humidityrelative_offset", &offset);
    read_file("/sys/bus/iio/devices/iio:device0/in_humidityrelative_scale", &scale);

    value = (raw + offset)*scale / 1000;

    return value;
}

int main()
{
    printf("tem: %.1f, hum: %.1f\n", read_tem(), read_hum());
    return 0;
}
